var root = ui("$");
var couponUrl = require("url/coupon");
var qqHttp = require("helper/http");
var nf = sm("do_Notification");
var helperOpen = require("helper/open");
// UI
// 设置数据绑定的映射关系
root.setMapping({ // 此处的Mapping只能设置在 RootView 上 ;
	"couponName.text" : "name",
	"couponName.tag" : "id",
	"do_ImageView_drawImg.source":"drawImg",
	"do_Label_expireAt.text":"strExpireAtU",
	"labelQnum.text":"minusPrice",
	"labelQnum.tag":"minusPrice",
	"do_Label_19.text":"bizzTypeDesc"
	
});

var buttonA = deviceone.mm("do_Animation", "BUTTONTOUCHDOWNS", "app");
var jia = ui("do_Button_1");
var jian = ui("do_Button_2");
var num = ui("labelNum");
var labelQnum = ui("labelQnum")
var max=99, min=0;
//+
jia.on("touch",function(){
	jia.animate(buttonA);
	num.text = num.text*1+1;
	labelQnum.text = num.text*labelQnum.tag;
	if(num.text*1>=max){
		num.text=max;
		labelQnum.text = max*labelQnum.tag;
		return;
	}
});
//-
jian.on("touch",function(){
	jian.animate(buttonA);
	num.text = num.text*1-1;
	labelQnum.text = num.text*labelQnum.tag;
	if(num.text*1<=min){
		num.text=min;
		labelQnum.text = min*labelQnum.tag;
		return;
	}
});

ui("showBgc").on("touch",function(){
	binddata();
})

function binddata() {
	var params = {
		couponId : ui("couponName").tag,
		quantity:num.text
	}
	qqHttp.post(couponUrl.url.user.buy, params, function(data) {
		helperOpen.open("source://view/coupon/manage/list.ui");
		nf.alert("兑换成功");
	});
}